/* Plot0.do (STATA)
	Plot IV.
	by Ralph Koijen & Motohiro Yogo */

#delimit ;
clear all;
set more off;
set type double;
set scheme s1mono;

cap log close;
log using Plot0, replace;

/* Define local and global variables */

local path = "../../figures";


/* Load data */

u year country counter_euro type IVLquant IVLdemand
	if year==2020 & country=="USA"
	using Estimation0, clear;

/* Keep unique observation for euro area */

duplicates drop;

/* Demean variables */

foreach var of varlist IVLquant IVLdemand {;
	egen M`var' = mean(`var'), by(type);

	replace `var' = `var'-M`var';

	drop M`var';
};

/* Specify panel labels */

label define type_label
	1 "A. Short-term debt"
	2 "B. Long-term debt"
	3 "C. Equity", replace;

/* Figure: Predicted log demand vs. predicted log supply */

twoway (scatter IVLdemand IVLquant, m(none) mlabel(counter_euro) mlabp(0))
	(lfit IVLdemand IVLquant, lc(gray)),
	by(type, cols(1) yr xr legend(off) note(""))
	ylabel(, angle(0))
	ytitle("Predicted log demand")
	xtitle("Predicted log supply")
	xsize(3) ysize(9);

graph export "`path'/IV.eps", replace;

twoway (scatter IVLdemand IVLquant, m(none) mlabel(counter_euro) mlabp(0))
	(lfit IVLdemand IVLquant, lc(gray)),
	by(type, rows(1) yr xr legend(off) note(""))
	ylabel(, angle(0))
	ytitle("Predicted log demand")
	xtitle("Predicted log supply")
	xsize(9) ysize(3);

graph export "`path'/IVL.eps", replace;

log close;
